from django.http import JsonResponse
import json


class ResultModel:
    code = 200
    msg = "success"
    data = ''

    def __init__(self, data='', msg="success", code=200):
        self.code = code
        self.data = data
        self.msg = msg

    @staticmethod
    def success(data='', msg="success"):
        return ResultModel(data, msg).toString()

    @staticmethod
    def error(msg='error', code=500):
        return ResultModel('', msg, code).toString()

    def toString(self):
        return JsonResponse(vars(self))
